/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc75;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc75Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc75QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc75Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-29
**/
@Service
@RequiredArgsConstructor
public class TransferIc75ServiceImpl extends ServiceImpl<TransferIc75Mapper, TransferIc75> implements TransferIc75Service {

    private final TransferIc75Mapper transferIc75Mapper;

    @Override
    public PageResult<TransferIc75> queryAll(TransferIc75QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc75Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc75> queryAll(TransferIc75QueryCriteria criteria){
        return transferIc75Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc75 resources) {
        transferIc75Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc75 resources) {
        TransferIc75 transferIc75 = getById(resources.getAaz635());
        transferIc75.copy(resources);
        transferIc75Mapper.updateById(transferIc75);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<BigDecimal> ids) {
        transferIc75Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc75> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc75 transferIc75 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc75.getAaz341());
            map.put("转出地行政区划代码", transferIc75.getAab301());
            map.put("转出地人员编号", transferIc75.getAac319());
            map.put("人员编号", transferIc75.getAac001());
            map.put("年度", transferIc75.getAae001());
            map.put("缴费起始时间", transferIc75.getAae041());
            map.put("缴费终止时间", transferIc75.getAae042());
            map.put("月数", transferIc75.getAae202());
            map.put("城镇职工基本养老保险信息表ID", transferIc75.getAaz086());
            map.put("转移数据来源", transferIc75.getAac306());
            map.put("人员参保关系ID", transferIc75.getAaz159());
            map.put("备注", transferIc75.getAae013());
            map.put("经办人", transferIc75.getAae011());
            map.put("经办时间", transferIc75.getAae036());
            map.put("经办机构", transferIc75.getAab359());
            map.put("业务日志ID", transferIc75.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
